package test11;

import java.net.Socket;
import java.sql.*;

public class Test {
    public static void main(String[] args)  {
        Connection conn=null;
        ResultSet rs=null;
        Statement stmt=null;
        PreparedStatement pstmt = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url="jdbc:mysql://localhost:3306/jdbc?serverTimezone=GMT";
            String username="root";
            String password="123456";

            conn= DriverManager.getConnection(url,username,password);
            stmt=conn.createStatement();
            String sqlAdd="insert into  student1(sno,sname,age,gender)values('8','wu',19,'男')";
            stmt.execute(sqlAdd);
            String sqlDelete="delete  from student1 where sno=1";
            stmt.execute(sqlDelete);
            String sqlAdd2="insert into  student1(sno,sname,age,gender)values('9','chen',19,'男')";
            pstmt=conn.prepareStatement(sqlAdd2);
            String sqlUpdate = "update student1 set sno = '999' where sno = 3";
            stmt.executeUpdate(sqlUpdate);
            String sqlFind="select * from student1";

            rs=stmt.executeQuery(sqlFind);
            System.out.println("id   |   name    |   age    |   gender");
            while(rs.next()){
                String id=rs.getString("sno");
                String name=rs.getString("sname");
                int age=rs.getInt("age");
                String gender=rs.getString("gender");
                System.out.println(id+"  |   "+name+"    |    "+age+"    |  "+gender);
            }

        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }
}
